package com.example.teamtribe.database;

import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.NonNull;

import org.litepal.crud.DataSupport;

public class TeamRequest extends DataSupport implements Parcelable, Comparable<TeamRequest> {

    private int id;
    private int realId;
    private int userId;
    private int teamId;
    private String requestReason;
    private int result;
    private String responseReason;
    private String createTime;
    private boolean isRead;

    public TeamRequest() {
    }

    @Override
    public int compareTo(@NonNull TeamRequest o) {
        return o.realId - realId > 0 ? 1 : -1;
    }

    public synchronized boolean saveOrUpdate() {
        return saveOrUpdate("realId = ?", realId + "");
    }

    @Override
    public int hashCode() {
        return realId;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == this)
            return true;
        if (obj instanceof TeamRequest) {
            TeamRequest request = (TeamRequest) obj;
            return request.realId == realId;
        }
        return false;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getRealId() {
        return realId;
    }

    public void setRealId(int realId) {
        this.realId = realId;
    }

    public int getUserId() {
        return userId;
    }

    public void setUserId(int userId) {
        this.userId = userId;
    }

    public int getTeamId() {
        return teamId;
    }

    public void setTeamId(int teamId) {
        this.teamId = teamId;
    }

    public String getRequestReason() {
        return requestReason;
    }

    public void setRequestReason(String requestReason) {
        this.requestReason = requestReason;
    }

    public int getResult() {
        return result;
    }

    public void setResult(int result) {
        this.result = result;
    }

    public String getResponseReason() {
        return responseReason;
    }

    public void setResponseReason(String responseReason) {
        this.responseReason = responseReason;
    }

    public String getCreateTime() {
        return createTime;
    }

    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }

    public boolean isRead() {
        return isRead;
    }

    public void setRead(boolean read) {
        isRead = read;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(this.id);
        dest.writeInt(this.realId);
        dest.writeInt(this.userId);
        dest.writeInt(this.teamId);
        dest.writeString(this.requestReason);
        dest.writeInt(this.result);
        dest.writeString(this.responseReason);
        dest.writeString(this.createTime);
        dest.writeByte(this.isRead ? (byte) 1 : (byte) 0);
    }

    protected TeamRequest(Parcel in) {
        this.id = in.readInt();
        this.realId = in.readInt();
        this.userId = in.readInt();
        this.teamId = in.readInt();
        this.requestReason = in.readString();
        this.result = in.readInt();
        this.responseReason = in.readString();
        this.createTime = in.readString();
        this.isRead = in.readByte() != 0;
    }

    public static final Creator<TeamRequest> CREATOR = new Creator<TeamRequest>() {
        @Override
        public TeamRequest createFromParcel(Parcel source) {
            return new TeamRequest(source);
        }

        @Override
        public TeamRequest[] newArray(int size) {
            return new TeamRequest[size];
        }
    };
}
